package com.spring.api.web.controller;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

import com.fasterxml.jackson.databind.util.JSONPObject;

import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.mangofactory.swagger.annotations.ApiIgnore;
import com.spera.genutil.TokenUtil;
import com.spera.genutil.tools;
import com.spring.security.core.util.ApplicationUtils;
import com.spring.security.web.dao.JedisCache;
import com.spring.security.web.model.User;
import com.spring.security.web.service.UserService;
import com.spring.sperapc.web.model.Family;
import com.spring.sperapc.web.model.FamilyMember;
import com.spring.sperapc.web.service.FamilyMemberService;
import com.spring.sperapc.web.service.UserDetailService;
import com.spring.sperapc.web.service.UserFamilyService;
//import com.spring.api.web.model.ApiUserDetail;

/**
 * 
 * @author wojunyu
 * 
 */
@Controller
@RequestMapping(value = "/userApi")
@ApiIgnore
public class UserApiController {
	static Logger logger = Logger.getLogger(UserApiController.class.getName());
	@Resource
	private UserService userService;
	@Resource
	private UserDetailService userDetailService;
	@Resource
	private JedisCache jedisCache;
	@Resource
	private UserFamilyService userFamilyService;
	@Resource
	private FamilyMemberService familyMemberService;


//	/**
//	 * 查询用户详细信息
//	 * 
//	 * @param token
//	 * @return
//	 */
//	@RequestMapping(value = "/queryUserDetail")
//	@ResponseBody
//	public Object queryUserDetail(String token, String callback) {
//		Map<String, Object> m = new HashMap<String, Object>();
//		try {
//			Map<String, Object> s = checkToken(token);
//			if (ApplicationUtils.isNotNull(s)) {
//				if (ApplicationUtils.isNotNull(callback))
//					return new JSONPObject(callback, s);
//				else
//					return s;
//			}
//
//			String user_id = redisCache.lindex(token,0);
//
//			UserDetail userDetail = userDetailService
//					.selectByPrimaryKey(user_id);
//			ApiUserDetail obj = new ApiUserDetail();
//			if (ApplicationUtils.isNotNull(userDetail)) {
//				obj.setId(userDetail.getId());
//				obj.setBirthday(userDetail.getBirthday());
//				obj.setName(userDetail.getName());
//				obj.setSex(userDetail.getSex());
//				obj.setWx_point(userDetail.getWx_point());
//				obj.setWork(userDetail.getWork());
//				obj.setAddress(userDetail.getAddress());
//				obj.setEducation(userDetail.getEducation());
//				obj.setPhone(userDetail.getPhone());
//				obj.setImage_src(userDetail.getImage_src());
//			}
//			List<ApiUserDetail> dataSet = new ArrayList<ApiUserDetail>();
//			dataSet.add(obj);
//			m.put(ApplicationUtils.DATASET, dataSet);
//			m.put(ApplicationUtils.STATUS, "1");
//			m.put(ApplicationUtils.MSG, "查询成功");
//		} catch (Exception e) {
//			m.put(ApplicationUtils.STATUS, "0");
//			m.put(ApplicationUtils.MSG, "系统异常");
//			e.printStackTrace();
//		}
//		if (ApplicationUtils.isNotNull(callback)){
//			System.out.println("---->"+new JSONPObject(callback, m));
//			return new JSONPObject(callback, m);
//		}else
//			return m;
//	}
//
//	/**
//	 * 保存用户详细信息（包括新增、修改）
//	 * 
//	 * @param token
//	 * @return
//	 */
//	@RequestMapping(value = "/saveUserDetail")
//	@ResponseBody
//	public Object saveUserDetail(UserDetail userDetail, String token,
//			String callback) {
//		Map<String, Object> m = new HashMap<String, Object>();
//		String ret = "";
//		try {
//			Map<String, Object> s = checkToken(token);
//			if (ApplicationUtils.isNotNull(s)) {
//				if (ApplicationUtils.isNotNull(callback))
//					return new JSONPObject(callback, s);
//				else
//					return s;
//			}
//			String user_id = redisCache.lindex(token,0);
//			userDetail.setcUserId(user_id);
//			int iss = 0;
//
//			UserDetail hasIn = userDetailService.selectByPrimaryKey(user_id);
//			if (ApplicationUtils.isNotNull(hasIn)
//					&& ApplicationUtils.isNotNull(hasIn.getId())) {
//				userDetail.setId(hasIn.getId());
//				iss = userDetailService.updateByPrimaryKeySelective(userDetail);
//			} else {
//				userDetail.setId(ApplicationUtils.randomUUID());
//				iss = userDetailService.insertSelective(userDetail);
//			}
//			if (iss == 0) {
//				ret = "操作失败";
//			} else {
//				ret = "操作成功";
//			}
//			m.put(ApplicationUtils.STATUS, "1");
//			m.put(ApplicationUtils.MSG, ret);
//		} catch (Exception e) {
//			m.put(ApplicationUtils.STATUS, "0");
//			m.put(ApplicationUtils.MSG, "系统异常");
//			e.printStackTrace();
//		}
//		if (ApplicationUtils.isNotNull(callback))
//			return new JSONPObject(callback, m);
//		else
//			return m;
//	}

	/**
	 * 查询家庭信息(包括了成员信息)v1.0
	 * 
	 * @param userDetail
	 * @param token
	 * @return
	 */
	@RequestMapping(value = "/queryFamily"/*,method=RequestMethod.POST*/)
	@ResponseBody
	public Object queryFamily(String token, String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			Map<String, Object> k = TokenUtil.checkToken(token,jedisCache);
			if (ApplicationUtils.isNotNull(k)) {
				if (ApplicationUtils.isNotNull(callback))
					return new JSONPObject(callback, k);
				else
					return k;
			}

			String user_id = jedisCache.hget(token,TokenUtil.USER_ID);
			logger.info("queryFamily----->user_id:"+user_id);
			Map<String, String> s = new HashMap<String, String>();
			s.put("c_user_id", user_id);
			Family family = userFamilyService.selectByPrimaryKey(s);
			List<Family> dataSet = new ArrayList<Family>();
			dataSet.add(family);
			m.put(ApplicationUtils.DATASET, dataSet);
			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "查询成功");
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback))
			return new JSONPObject(callback, m);
		else
			return m;
	}

	/**
	 * 保存家庭信息（包括新增、修改）v1.0
	 * 
	 * @param token
	 * @return
	 */
	@RequestMapping(value = "/saveUserFamily"/*,method=RequestMethod.POST*/)
	@ResponseBody
	public Object saveUserFamily(Family family, String token, String callback){
		Map<String, Object> m = new HashMap<String, Object>();
		String ret = "";
		try {
			Map<String, Object> k = TokenUtil.checkToken(token,jedisCache);
			if (ApplicationUtils.isNotNull(k)) {
				if (ApplicationUtils.isNotNull(callback))
					return new JSONPObject(callback, k);
				else
					return k;
			}

			String user_id = jedisCache.hget(token,TokenUtil.USER_ID);
			logger.info("saveUserFamily----->user_id:"+user_id);
			User u = new User();
			u.setId(user_id);
			// Map<String, Object> retD = new HashMap<String, Object>();
			//家庭信息更新
			if (ApplicationUtils.isNotNull(family.getId())) {
				userFamilyService.updateByPrimaryKeySelective(family);
				m.put(ApplicationUtils.STATUS, "1");
				ret = "操作成功";
			} else {//家庭信息新增
				//判断家庭是否已存在
				Map<String, String> s = new HashMap<String, String>();
				s.put("c_user_id", user_id);
				Family isIn = userFamilyService.selectByPrimaryKey(s);
				if(!ApplicationUtils.isNotNull(isIn)){
					family.setId(ApplicationUtils.randomUUID());
					userFamilyService.insertSelective(family, u);
					m.put(ApplicationUtils.STATUS, "1");
					ret = "操作成功";
				}else{
					m.put(ApplicationUtils.STATUS, "0");
					ret = "家庭已存在,请刷新后重试";
				}
			}
			m.put(ApplicationUtils.MSG, ret);
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}
		if (ApplicationUtils.isNotNull(callback))
			return new JSONPObject(callback, m);
		else
			return m;
	}

	/**
	 * 查询家庭成员v1.0
	 * 
	 * @param family
	 * @param token
	 * @return
	 */
	@RequestMapping(value = "/queryFamilyMember"/*,method=RequestMethod.POST*/)
	@ResponseBody
	public Object queryFamilyMember(String c_family_member_id,
			String c_family_id, String token, String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			Map<String, Object> k = TokenUtil.checkToken(token,jedisCache);
			if (ApplicationUtils.isNotNull(k)) {
				if (ApplicationUtils.isNotNull(callback))
					return new JSONPObject(callback, k);
				else
					return k;
			}

			String user_id = jedisCache.hget(token,TokenUtil.USER_ID);
			logger.info("queryFamilyMember----->user_id:"+user_id);
			Map<String, String> s = new HashMap<String, String>();
			s.put("id", c_family_member_id);
			s.put("c_family_id", c_family_id);
			s.put("c_user_id", user_id);

			List<FamilyMember> familyMemList = familyMemberService
					.selectByFamilyId(s);

			m.put(ApplicationUtils.DATASET, familyMemList);
			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "查询成功");
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}
		if (ApplicationUtils.isNotNull(callback))
			return new JSONPObject(callback, m);
		else
			return m;
	}

	/**
	 * 新增家庭成员v1.0
	 * 
	 * @param family
	 * @param token
	 * @return
	 */
	@RequestMapping(value = "/saveMember"/*,method=RequestMethod.POST*/)
	@ResponseBody
	public Object saveMember(FamilyMember familyMember, String token,
			String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		String ret = "";
		try {
			Map<String, Object> k = TokenUtil.checkToken(token,jedisCache);
			if (ApplicationUtils.isNotNull(k)) {
				if (ApplicationUtils.isNotNull(callback))
					return new JSONPObject(callback, k);
				else
					return k;
			}
			String user_id = jedisCache.hget(token,TokenUtil.USER_ID);
			logger.info("saveMember----->user_id:"+user_id);
			
			if(!ApplicationUtils.isNotNull(familyMember.getName())){
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "姓名不可为空");
			//	return m;
			}
			else if(!ApplicationUtils.isNotNull(familyMember.getSexCode())){
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "性别不可为空");
			//	return m;
			}
			else if(!ApplicationUtils.isNotNull(familyMember.getBirthday())){
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "生日不可为空");
			//	return m;
			}
			else if(!ApplicationUtils.isNotNull(familyMember.getMemberName())){
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "称谓不可为空");
			//	return m;
			}
			else if(!ApplicationUtils.isNotNull(familyMember.getcRoleId())){
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "角色不可为空");
			//	return m;
			}
			
			else if(!ApplicationUtils.isNotNull(familyMember.getcFamilyId())){
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "家庭不可为空");
			//	return m;
			}
			else {
				int iss = 0;
				familyMember.setcFamilyMemberId(ApplicationUtils.randomUUID());
				iss = familyMemberService.insertSelective(familyMember);
	
				if (iss == 0) {
					ret = "操作失败";
				} else {
					ret = "操作成功";
				}
				m.put(ApplicationUtils.STATUS, "1");
				m.put(ApplicationUtils.MSG, ret);
			}
			
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}
		if (ApplicationUtils.isNotNull(callback))
			return new JSONPObject(callback, m);
		else
			return m;
	}
	
	/**
	 * 更新家庭成员信息v1.0
	 * @param familyMember
	 * @param token
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/updateMember"/*,method=RequestMethod.POST*/)
	@ResponseBody
	public Object updateMember(FamilyMember familyMember, String token,
			String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		String ret = "";
		try {
			Map<String, Object> k = TokenUtil.checkToken(token,jedisCache);
			if (ApplicationUtils.isNotNull(k)) {
				if (ApplicationUtils.isNotNull(callback))
					return new JSONPObject(callback, k);
				else
					return k;
			}
			String user_id = jedisCache.hget(token,TokenUtil.USER_ID);
			logger.info("updateMember----->user_id:"+user_id);
			int iss = 0;
//			if (ApplicationUtils.isNotNull(familyMember.getcFamilyId())) {
				iss = familyMemberService
						.updateByPrimaryKeySelective(familyMember);
//			}
			if (iss == 0) {
				ret = "操作失败";
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, ret);
			} else {
				ret = "操作成功";
				m.put(ApplicationUtils.STATUS, "1");
				m.put(ApplicationUtils.MSG, ret);
			}
		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}
		if (ApplicationUtils.isNotNull(callback))
			return new JSONPObject(callback, m);
		else
			return m;
	}


//	/**
//	 * 宝宝 用户详细信息
//	 * 
//	 * @param token
//	 * @return
//	 */
//	@RequestMapping(value = "/queryUBabyDetail")
//	@ResponseBody
//	public Object queryUBabyDetail(String token, String callback) {
//		Map<String, Object> m = new HashMap<String, Object>();
//
//		try {
//
//			Map<String, Object> k = checkToken(token);
//			if (ApplicationUtils.isNotNull(k)) {
//				if (ApplicationUtils.isNotNull(callback))
//					return new JSONPObject(callback, k);
//				else
//					return k;
//			}
//
//			String user_id = redisCache.lindex(token,0);
//
//			Baby babyDetail = userDetailService.selectBabyByPrimaryKey(user_id);
//
//			List<Baby> dataSet = new ArrayList<Baby>();
//			dataSet.add(babyDetail);
//			m.put(ApplicationUtils.DATASET, dataSet);
//			m.put(ApplicationUtils.STATUS, "1");
//			m.put(ApplicationUtils.MSG, "查询成功");
//		} catch (Exception e) {
//			m.put(ApplicationUtils.STATUS, "0");
//			m.put(ApplicationUtils.MSG, "系统异常");
//			e.printStackTrace();
//		}
//		if (ApplicationUtils.isNotNull(callback))
//			return new JSONPObject(callback, m);
//		else
//			return m;
//	}
//
//	/**
//	 * 保存宝宝用户详细信息（包括新增、修改）
//	 * 
//	 * @param token
//	 * @return
//	 */
//	@RequestMapping(value = "/saveUBabyDetail")
//	@ResponseBody
//	public Object saveUBabyDetail(Baby baby, String token, String callback) {
//		Map<String, Object> m = new HashMap<String, Object>();
//
//		String ret = "";
//		try {
//
//
//			Map<String, Object> k = checkToken(token);
//			if (ApplicationUtils.isNotNull(k)) {
//				if (ApplicationUtils.isNotNull(callback))
//					return new JSONPObject(callback, k);
//				else
//					return k;
//			}
//
//			String user_id = redisCache.lindex(token,0);
//			baby.setcUserId(user_id);
//			int iss = 0;
//			if (ApplicationUtils.isNotNull(baby.getId())) {
//				iss = userDetailService.updateBabyByPrimaryKey(baby);
//			} else {
//				baby.setId(ApplicationUtils.randomUUID());
//				iss = userDetailService.insertBabySelective(baby);
//			}
//
//			if (iss == 0) {
//				ret = "操作失败";
//			} else {
//				ret = "操作成功";
//			}
//			m.put(ApplicationUtils.STATUS, "1");
//			m.put(ApplicationUtils.MSG, ret);
//		} catch (Exception e) {
//			m.put(ApplicationUtils.STATUS, "0");
//			m.put(ApplicationUtils.MSG, "系统异常");
//			e.printStackTrace();
//		}
//		if (ApplicationUtils.isNotNull(callback))
//			return new JSONPObject(callback, m);
//		else
//			return m;
//	}

	@RequestMapping(value = "/updateWxPoint"/*,method=RequestMethod.POST*/)
	@ResponseBody
	public Object updateWxPoint(String token, String wx_point, String callback) {
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			Map<String, Object> s = TokenUtil.checkToken(token,jedisCache);
			if (ApplicationUtils.isNotNull(s)) {
				if (ApplicationUtils.isNotNull(callback))
					return new JSONPObject(callback, s);
				else
					return s;
			}

			String user_id = jedisCache.hget(token,TokenUtil.USER_ID);
			int effect = userDetailService.updateWxPoint(user_id, wx_point);
			if (effect == 1) {
				m.put(ApplicationUtils.STATUS, "1");
				m.put(ApplicationUtils.MSG, "修改成功");
			} else {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "修改失败");
			}

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();
		}
		if (ApplicationUtils.isNotNull(callback))
			return new JSONPObject(callback, m);
		else
			return m;
	}

	
	
	
	
	
	 @RequestMapping(value = "/updateUserImageSrc")
	    @ResponseBody
	    public Object updateTeacherImage(String token,MultipartFile file,String callback, HttpServletRequest request)throws Exception {
	    	
	    	Map<String,Object> m = new HashMap<String,Object>();
	    	if(!ApplicationUtils.isNotNull(token)){
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "请先登录");
				if(ApplicationUtils.isNotNull(callback))
	            return new JSONPObject(callback, m);
	            else return m;
			}
	    	try{
	    		if(!ApplicationUtils.isNotNull(token)){
		            if(!jedisCache.exists(token)){
		            	m.put(ApplicationUtils.STATUS, "0");
		                m.put(ApplicationUtils.MSG,"用户未登录，请先登录");
		                if(ApplicationUtils.isNotNull(callback))
		                return new JSONPObject(callback, m);
		                else return m;
		            }
	    		}
//	    		System.out.println(token+"token");
	            String user_id = jedisCache.hget(token,TokenUtil.USER_ID);
	            
	            if(user_id==null){
	            	m.put(ApplicationUtils.STATUS, "0");
	                m.put(ApplicationUtils.MSG,"用户未登录，请先登录");
	            }
	            
//	            System.out.println("user_id"+user_id);
	            
	            if (!file.isEmpty()) {
	                String fileName = file.getOriginalFilename();
	                
	                String type=tools.getFileType(fileName);
	                
	                file.getContentType();
	                
//	                System.out.println("type"+file.getContentType());
//	                Date d = new Date();
	                //SimpleDateFormat tempDate = new SimpleDateFormat("yyyyMMddHHmmss");
	                String newfilename = ApplicationUtils.randomUUID()+"."+type;
	                Integer fileSize = 0;
	                File filePath = null;
	                byte[] bytes = file.getBytes();
	                fileSize = (int) file.getSize() / 1024;
	                if (fileSize <= 102400) {
	                    //String path = request.getRealPath("");
	                	
	                	String uploadStr="upload"+File.separator+"image";
	                	
	                	String uploadPath = request.getSession().getServletContext().getRealPath(uploadStr);    	
	                	
	                	String root=request.getSession().getServletContext().getRealPath("");
	                	
	                	
	                   // String uploadPath = "\\upload\\";
	                    //String uploadPath = JedisCont.APP_ADDRESS;
	                    if(!(new File(uploadPath).isDirectory())){
	                        new File(uploadPath).mkdirs();
	                    }
	                    uploadPath+=File.separator+newfilename;
	                    
	                    
	                    int effect=userDetailService.updateUserImageSrc(user_id, File.separator+uploadStr+File.separator+newfilename, root);
	                    
	                    System.out.println("image_src"+File.separator+uploadStr+File.separator+newfilename);
	                    
	                   // 		updateTeacherImage(user_id, "/"+uploadStr+"/"+newfilename, root);
	                 //   int effect=userDetailService.updateUserImageSrc(user_id, "/"+uploadStr+"/"+newfilename,root);
	                    
	                    
	                    if(effect==1){
	                    	m.put(ApplicationUtils.STATUS, "1");
	                        m.put(ApplicationUtils.MSG,"修改成功");
	                        m.put("image_src",File.separator+uploadStr+File.separator+newfilename);
	                    }else{
	                    	m.put(ApplicationUtils.STATUS, "0");
	                        m.put(ApplicationUtils.MSG,"系统异常");
	                    }
	                    
	                    
	                    
	                    
	                    filePath = new File(uploadPath);
	                    FileCopyUtils.copy(bytes, filePath);
	                    
	                    System.out.println(uploadPath);
	                    
	                    
	                    System.out.println("user_id"+user_id);
	                    
	                    System.out.println("上传成功");
	                    
	                    
	                    //user.setImage_src(JedisCont.APP_ADDRESS+newfilename);
	                } else {
	                    m.put(ApplicationUtils.STATUS, "0");
	                    m.put(ApplicationUtils.MSG,"上传的文件太大，文件大小不能超过10M");
	                    if (ApplicationUtils.isNotNull(callback))
	            			return new JSONPObject(callback, m);
	            		else
	            			return m;
	                }
	            }else{
	            	m.put(ApplicationUtils.STATUS, "0");
	                m.put(ApplicationUtils.MSG,"请选择上传的文件");
	            }
	            
	          
	            
	    	}catch (Exception e){
	        	m.put(ApplicationUtils.STATUS, "0");
	            m.put(ApplicationUtils.MSG,"系统异常");
	            e.printStackTrace();
	        }
	    	
	    	if (ApplicationUtils.isNotNull(callback))
				return new JSONPObject(callback, m);
			else
				return m;
	    }
	
	
	
	
	
	// 检查token
//	private Map<String, Object> checkToken(String token) {
//		Map<String, Object> s = new HashMap<String, Object>();
//		if (!ApplicationUtils.isNotNull(token)) {
//			s.put(ApplicationUtils.STATUS, "0");
//			s.put(ApplicationUtils.MSG, "请先登录");
//			return s;
//		} else {
//			//System.out.println("token type----------->"+(token instanceof String));
//			if (!jedisCache.exists(token)) {
//				s.put(ApplicationUtils.STATUS, "-9999");
//				s.put(ApplicationUtils.MSG, "用户登录已失效，请先重新登录");
//				return s;
//			} else {
//				jedisCache.expire(token, JedisCont.JEDIS_EXPRISE);
//				return null;
//			}
//		}
//	}
	
	 @RequestMapping(value = "/checkLogin")
	 @ResponseBody
	 public Object checkLogin(String token,String callback) {
		 Map<String, Object> s = TokenUtil.checkToken(token,jedisCache);
		 if (!ApplicationUtils.isNotNull(s)) {
			 s = new HashMap<String, Object>();
			 s.put(ApplicationUtils.STATUS, "1");
			 s.put(ApplicationUtils.MSG, "有效用户");
		 }
		 if (ApplicationUtils.isNotNull(callback))
				return new JSONPObject(callback, s);
			else
				return s;
	 }
	 
	 /**
	  * 登出
	  * @param token
	  * @param callback
	  * @return
	  */
	 @RequestMapping(value = "/logOut")
	 @ResponseBody
	 public Object logOut(String token,String callback) {
		 Map<String, Object> s = TokenUtil.checkToken(token,jedisCache);
		 if (!ApplicationUtils.isNotNull(s)) {
			 s = new HashMap<String, Object>();
			 jedisCache.del(token);
			 s.put(ApplicationUtils.STATUS, "1");
			 s.put(ApplicationUtils.MSG, "欢迎下次光临");
		 }
		 if (ApplicationUtils.isNotNull(callback))
				return new JSONPObject(callback, s);
			else
				return s;
	 }

}
